/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presistencia;

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *class que gerencia a conexao com o banco 
 * 
 * Data 21/03/12
 * @author Marcelo Paiva (Meticore)
 */
public class Dao {
    
     
    
    public static String [][]conectaBanco(String query , int lin , int col) {
         
        String [][]result = new String[lin][col];
        
            
         try{
        
            String driver = "org.postgresql.Driver";
            String user   = "postgres";
            String senha  = "Salsul0123";
            String url    = "jdbc:postgresql://192.168.40.3:5432/manutencao";


            Class.forName(driver);

            Connection con = (Connection) DriverManager.getConnection(url, user, senha);
            Statement stm = con.createStatement();

            
            ResultSet rs = stm.executeQuery(query);
            boolean next = rs.next();
            
       
            for ( int cont = 0 ; cont < lin ;cont++){
                for ( int cont2 = 0 ; cont2 < col ;cont2++){
                    
                    result[cont][cont2] = rs.getString("col"+cont2);
                    
                    
                }
            }
            
           
            
         //   boolean next = rs.next();
           
        con.close();    
            
        } catch (ClassNotFoundException ex) {
            System.err.print(ex.getMessage());
        } catch (SQLException e) {
            System.err.print(e.getMessage());
        }
        
        return result;
    }
    
    
    // metodos com as query do sistema 
    
    
    //busca dados do chamado 
    
    
    public static String dadosChamado (String id){
        
        int lin = 1 ;
        int col = 7 ;
        
        String query = "SELECT num_os as col0, solicitante as col1, setor as col2, prioridade as col3, data_inicio as col4,"
                     + "descricao as col5, tipo as col6"
                     + "FROM os_manutencao"
                     + "where num_os = '" + id +"'";
              
        
        return query;
    }
    
    
    public static String gravaDados (String [][]dados , int id){
        
        
        int col = 6 ;
        
        
        String query = "INSERT INTO reparo( desc_tarefa as col0, data_hora_inicio as col1, data_hora_final as col2,"
                     + " duracao_reparo as col3, cod_manutentor as col4)"
                     + "VALUES (?, ?, ?, ?, ?);";
      
        
        return query ;
        
    }
     
        
}